import Vue from 'vue'
import VueRouter from 'vue-router'
// import { component } from 'vue/types/umd'
import manage from '../views/manage.vue'
import Login from './../views/Login.vue'
import lzpRouter from './lzpRouter'
import zxRouter from './zxRouter'
import hmlRouter from './zxRouter'
import hjRouter from './hjRouter'
import cyhRouter from './zxRouter'
import wwRouter from './zxRouter'
Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Login',
        component: Login,
        meta: { title: '登录' }
    },
    // 用户端路由
    {
        path: '/manage',
        name: 'manage',
        component: manage,
        children: [
            ...lzpRouter,
            ...zxRouter,
            ...hmlRouter,
            ...hjRouter,
            ...cyhRouter,
            ...wwRouter,
            {
                path: 'no',
                component: () =>
                    import ('./../components/common/no.vue'),
            },
            {
                path: '404',
                component: () =>
                    import ('./../components/common/404.vue'),
                hidden: true
            },

        ]
    },

    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/manage/404', hidden: true }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//         return originalPush.call(this, location).catch(err => err)
//     }
// 在前置路由守卫：
// router.beforeEach((to, from, next) => {

//     })
// 后置路由守卫：
router.afterEach((to, form) => {
    // console.log(to.meta.title)
    let title = to.meta.title;
    title = title == undefined ? '互联网医院平台' : title;

    document.title = title;
})
export default router